<template>
	<pro-table
		ref="protable"
		:loadDataUrl="api.getList"
		:orgId="globalOrgId"
		:extendParam="{
			orgId: globalOrgId,
		}"
		rowKey="deptId"
		:showPagination="false"
		:columns="columns"
		:isRowSelection="false"
		:isAdd="$_has('sys:dept:insert')"
		:isDelete="$_has('sys:dept:delete')"
		@addRecord="addRecord"
		@setTableData="setTableData"
	>
		<a-tag
			style="border-radius: 50px"
			:color="depttypecolorlist[text]"
			slot="deptType"
			slot-scope="{ text, record }"
			>{{ depttypelist[text] }}</a-tag
		>
		<span slot="operation" slot-scope="{ text, record }" class="operation">
			<a href="javascript:;" title="编辑" v-has="'sys:dept:update'" class="edit" @click="editRecord(record)"
				>编辑</a
			>
			<a href="javascript:;" title="新增" v-has="'sys:dept:insert'" class="add" @click="addRecord(record)"
				>新增</a
			>
			<a
				href="javascript:;"
				title="删除"
				v-has="'sys:dept:delete'"
				class="del"
				@click="showDeleteConfirm(1, record.deptId, record.deptName)"
				>删除</a
			>
		</span>
		<!-- 权限 -->
		<!-- 添加，编辑  -->
		<addOrEditDeptModal
			editKey="deptId"
			:api="api"
			modalTitle="部门"
			ref="addOrEditModal"
			@ok="handlerRefresh"
		></addOrEditDeptModal>
	</pro-table>
</template>

<script>
import { rowSelection, recordOperation } from '@/mixins'
import { sysManageapi } from '@/api/index.js'
import addOrEditDeptModal from './module/addOrEditDeptModal'
import { mapState, mapMutations } from 'vuex'
const columns = [
	{
		title: '部门名称',
		dataIndex: 'deptName',
		key: 'deptName',
		ellipsis: true,
		width:250
	},
	{
		title: '所属机构',
		dataIndex: 'orgName',
		key: 'orgName',
		ellipsis: true,
		width:250
		
	},
	{
		title: '排序',
		dataIndex: 'orderNum',
		key: 'orderNum',
		width: '10%',
	},

	{
		title: '操作',
		key: 'operation',
		dataIndex: 'operation',
		scopedSlots: {
			customRender: 'operation',
		},
		align: 'left',
		width: 160,
	},
]
export default {
	name: 'deptlist',
	mixins: [rowSelection, recordOperation],
	components: {
		addOrEditDeptModal,
	},
	data() {
		return {
			columns: columns,
			filter: {},
			api: sysManageapi.deptUrl,
		}
	},
	created() {},
	methods: {
		...mapMutations(['SET_ALLDEPTTREE']),
		/* 刷新列表当前页 */
		handlerRefresh() {
			this.$refs.protable.handlerRefresh()
		},

		setTableData(tree) {
			this.SET_ALLDEPTTREE(tree)
		},
		/* 新增 */
		addRecord(record) {
			let param = null
			if (!!record) {
				let { deptId, orgId } = record
				param = { parentId: deptId, orgId }
			}

			this.$refs.addOrEditModal.add(param)
		},
	},
}
</script>

<style scoped="scoped" lang="less"></style>
